package com.time.sky.controller;

import com.time.sky.entity.Binfo;
import com.time.sky.mapper.BinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/Binfo")
public class BinfoController {
    @Autowired
    private BinfoMapper binfoMapper;
    @ResponseBody
    @RequestMapping("/rows")
    public int rows(){
        return binfoMapper.getRowCount();
    }
    @ResponseBody
    @RequestMapping("/select")
    public List<Binfo> selectList(){   return binfoMapper.selectList(); }
    @RequestMapping("/add")
    public void add(Binfo binfo){
        binfoMapper.add(binfo);
    }
    @RequestMapping("/delete")
    public void delete(int bid){
        binfoMapper.delete(bid);
    }
    @RequestMapping("/get/{bid}")
    public Binfo getById(@PathVariable("bid") int bid){
        return binfoMapper.getById(bid);
    }
    @RequestMapping("/update")
    public void update(Binfo binfo){
        binfoMapper.update(binfo);
    }
    @ResponseBody
    @RequestMapping("/mohu")
    public List<Binfo> selectBinfoById(Binfo binfo){
        return binfoMapper.selectById(binfo);
    }
    @RequestMapping("/deleteBatch")
    public void deleteBatch(String ids) {
        if (ids != null && !ids.equals("") && !ids.equals("null")) {
            String[] idArr = ids.split(",");
            List<Integer> idList = new ArrayList<Integer>();
            for (String id : idArr) {
                idList.add(Integer.parseInt(id));
            }
            binfoMapper.deleteBatch(idList);
        }
    }
}
